package com.zyz.K_集合.Map接口一HashMap.练习;

import java.util.HashMap;

/**
 * @author: vick
 * @Date: 2025/3/30
 * @Description:
 * @version: 1.0
 */
public class Demo3 {
    public static void main(String[] args) {
        String str = "aaaabbbcccccccccc";
        char[] charArray = str.toCharArray();
        HashMap hashMap = new HashMap();
        for (char c : charArray) { // 遍历字符数组
            if (!hashMap.containsKey(c)) {//如果不存在key
                hashMap.put(c, 1);
            }else {
                int count = (int) hashMap.get(c);
                hashMap.put(c, count + 1);
            }
        }

        for (Object key : hashMap.keySet()) {
            System.out.println(key + "=" + hashMap.get(key));
        }
    }
}
